﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DIProject.ReceptionGoods
{
    public partial class WaybillsSumForm : Form
    {
        public WaybillsSumForm()
        {
            InitializeComponent();
        }

        private void WaybillsSumForm_Load(object sender, EventArgs e)
        {
            InitPeriod();
            InitData();
        }
        void InitPeriod()
        {
            var dt = DateTime.Now.Date;
            dtpStart.Value = dt.AddMonths(-1);
            dtpEnd.Value = dt;
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            InitData();
        }
        void InitData()
        {
            if (dtpStart.Value >= dtpEnd.Value)
            {
                MessageBox.Show("Дата окончания периода должна быть больше даты начала!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var data = Data.Waybills.GetSelectData(dtpStart.Value, dtpEnd.Value);
            lblCount.Text = "Всего строк " + data.Count;
            BindingList<Data.WaybillSumSelectResult> ds = new BindingList<Data.WaybillSumSelectResult>(data);
            this.dvgWayBills.DataSource = ds;
        }
    }
}
